home *** CD-ROM | disk | FTP | other *** search
Text File | 2001-02-27 | 2.0 KB | 75 lines | [AMAS/AMAP] |
- // -* MoveBehavior.js *-
- //
- // Name: Move behavior
- // Description:
- // Author:
- // Version: $Id: MoveBehavior.js,v 1.3 2001/02/21 11:23:41 consumer Exp $
- //
-
- // Keep an array of the solids using this behavior
- var moveSolids = new Array(1);
-
- function MoveBehavior(solidName, intensity, position)
- {
- // Member methods of the behavior
- this.start = MoveBehaviorStart;
- this.stop = MoveBehaviorStop;
-
- // Member variables of the behavior
- this.solidName = solidName;
- this.position = position;
- this.intensity = intensity * TSSolidGetMass(solidName);
-
- // Make a drag and a damping force
- this.dragID = TSMakeUniqID("DragForce_" + solidName);
- TSMakeDragForce(this.dragID, this.intensity, "0 0 0", TSMakeStringFromPoint(TSSolidGetPosition(solidName)));
- this.dampID = TSMakeUniqID("DampingForce_" + solidName);
- TSMakeDampingSolidForce(this.dampID, "1", "1");
-
- TSAppendChild(solidName, this.dragID);
- TSAppendChild(solidName, this.dampID);
- TSUpdateNode(solidName);
- TSDropSolid(solidName);
- }
-
- function MoveBehaviorStart()
- {
- solidPosition = TSSolidGetPosition (this.solidName) ;
- translate = TSMakePointFromString (this.position) ;
- solidPosition.x = solidPosition.x + translate.x ;
- solidPosition.y = solidPosition.y + translate.y ;
- solidPosition.z = solidPosition.z + translate.z ;
- newPosition = solidPosition.x + " " + solidPosition.y + " " + solidPosition.z ;
-
- TSUpdateNodeAttribute(this.dragID, "targetPoint", newPosition);
- }
-
- function MoveBehaviorStop()
- {
- }
-
- //
- // Event functions
- //
-
- function MoveBehaviorStartEvent(obj, event)
- {
- if (moveSolids[obj] == null) {
- var speed = TSGetExtraParam(event, 'speed');
- var position = TSGetExtraParam(event, 'position');
- var targetSolid = TSGetExtraParam(event, 'targetSolid');
-
- if (targetSolid == "")
- moveSolids[obj] = new MoveBehavior(obj, speed, position);
- else
- moveSolids[obj] = new MoveBehavior(targetSolid, speed, position);
- }
-
- moveSolids[obj].start();
- }
-
- function MoveBehaviorStopEvent(obj, event)
- {
- moveSolids[obj].stop();
- }
-